package invoice;

import invoice.line.Line;
import java.util.LinkedList;

class LineList {
    private LinkedList<Line> lineList;

    public LineList(){
        lineList= new LinkedList<>();
    }

    public void add(Invoice line){
        lineList.add((Line)line);
    }

    public void add(Invoice[] line){
        for(Invoice l:line)
            lineList.add((Line) l);
    }

    public void decorate(){
        for(int i=lineList.size()-1;i>0;i--) {
            if (lineList.get(i) != null) {
                lineList.get(i).decorate(lineList.get(i - 1));
                lineList.get(i).setNum(i);
            }
            else {
                System.out.println("有发票行为空！");
                System.exit(0);
            }
        }
    }

    public void print(){
        lineList.getLast().print();
    }
}
